﻿Public Class ListadoPrestamos

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        If Me.txt_numDoc.Text = "" Then
            MsgBox("No ingresó el número de documento", MsgBoxStyle.Critical, "Error")
        Else
            Dim report As New CrystalReport2
            Dim consulta As String
            Dim conexion As New OleDb.OleDbConnection

            Dim ds_local As New DataSetPrestamos

            conexion.ConnectionString = "Provider=SQLOLEDB;Data Source=GTºN1\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=C:\DB\LIBRERIA_MAGOO.MDF"
            conexion.Open()
            Dim comando As New OleDb.OleDbCommand
            comando.Connection = conexion
            comando.CommandType = CommandType.Text

            consulta = "SELECT Cliente.num_doc as num_doc, Cliente.apellido+ ', ' + Cliente.nombre as apellido, DetallePrestamo.IdPrestamo as IdPrestamo, Libro.titulo as titulo, Prestamo.FechaInicio as FechaInicio, Prestamo.FechaFin as FechaFin FROM Libro, DetallePrestamo, Prestamo, Cliente where (Cliente.num_doc = " & Me.txt_numDoc.Text & ") and Libro.ISBN = DetallePrestamo.ISBN and DetallePrestamo.IdPrestamo = Prestamo.IdPrestamo and Prestamo.IdCliente = Cliente.id_cliente"

            comando.CommandText = consulta

            ds_local.ListadoPrestamos.Load(comando.ExecuteReader())

            conexion.Close()

            report.SetDataSource(ds_local)

            Me.crvListadoPrestamos.ReportSource = report
            Me.crvListadoPrestamos.Show()
            Me.crvListadoPrestamos.Refresh()

        End If
    End Sub
End Class